package com.cl.utils;


import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Random;

@Component
public class CodeUtil {
    public String getCode() {
        String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789";
        Random ran = new Random();
        char[] chars = new char[4];
        //验证码显示字符个数为4
        for (int i = 1; i <= 4; i++) {
            int index = ran.nextInt(str.length());
            //获取字符
            char ch = str.charAt(index);//随机字符
            chars[i - 1] = ch;
        }
        String code = new String(chars);
        return code;
    }
}

